/// 应用异常基类
abstract class AppException implements Exception {
  final String message;
  final int? code;
  final dynamic data;

  const AppException(this.message, {this.code, this.data});

  @override
  String toString() => message;
}

/// 网络异常
class NetworkException extends AppException {
  const NetworkException(String message, {int? code, dynamic data})
    : super(message, code: code, data: data);
}

/// API异常
class ApiException extends AppException {
  const ApiException(String message, {int? code, dynamic data})
    : super(message, code: code, data: data);
}

/// 认证异常
class AuthException extends AppException {
  const AuthException(String message, {int? code, dynamic data})
    : super(message, code: code, data: data);
}

/// 表单验证异常
class ValidationException extends AppException {
  const ValidationException(String message, {int? code, dynamic data})
    : super(message, code: code, data: data);
}

/// 未授权异常
class UnauthorizedException extends AuthException {
  const UnauthorizedException([String message = '未授权访问'])
    : super(message, code: 401);
}

/// 未认证异常
class UnauthenticatedException extends AuthException {
  const UnauthenticatedException([String message = '未登录或登录已过期'])
    : super(message, code: 401);
}

/// 令牌过期异常
class TokenExpiredException extends AuthException {
  const TokenExpiredException([String message = '登录已过期，请重新登录'])
    : super(message, code: 401);
}

/// 用户名或密码错误异常
class InvalidCredentialsException extends AuthException {
  const InvalidCredentialsException([String message = '用户名或密码错误'])
    : super(message, code: 401);
}

/// 用户已存在异常
class UserExistsException extends AuthException {
  const UserExistsException([String message = '用户已存在'])
    : super(message, code: 409);
}
